package com.netposa.datawarehouse.aggregator.web.rest;

import com.netposa.appwebres.WebResCallback;
import com.netposa.appwebres.common.WebResCriteria;
import com.netposa.appwebres.common.WebResInfo;
import com.netposa.appwebres.exception.WebResException;
import com.netposa.datawarehouse.aggregator.service.RegisterService;
import com.netposa.library.datawarehouse.aggregate.model.ModuleInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping({"/register"})
public class RegisterController {
   private static final Logger log = LoggerFactory.getLogger(RegisterController.class);
   @Autowired
   private RegisterService registerService;

   @PostMapping
   public WebResInfo register(@RequestBody final ModuleInfo moduleInfo) {
      return (new WebResCallback() {
         public void execute(WebResCriteria criteria, Object... params) {
            try {
               criteria.addSingleResult(RegisterController.this.registerService.registerModule(moduleInfo));
            } catch (WebResException var4) {
               throw var4;
            } catch (Exception var5) {
               RegisterController.log.error(var5.getMessage(), var5);
               throw new WebResException("500", new Object[]{"聚合服务注册机制异常"});
            }
         }
      }).sendRequest(new Object[0]);
   }

   @PostMapping({"/list"})
   public WebResInfo list(final ModuleInfo moduleInfo) {
      return (new WebResCallback() {
         public void execute(WebResCriteria criteria, Object... params) {
            try {
               criteria.addSingleResult(RegisterController.this.registerService.modules(moduleInfo));
            } catch (WebResException var4) {
               throw var4;
            } catch (Exception var5) {
               RegisterController.log.error(var5.getMessage(), var5);
               throw new WebResException("500", new Object[]{"聚合服务注册查询异常"});
            }
         }
      }).sendRequest(new Object[0]);
   }

   @PostMapping({"/del"})
   public WebResInfo del(final ModuleInfo moduleInfo) {
      return (new WebResCallback() {
         public void execute(WebResCriteria criteria, Object... params) {
            try {
               criteria.addSingleResult(RegisterController.this.registerService.delete(moduleInfo));
            } catch (WebResException var4) {
               throw var4;
            } catch (Exception var5) {
               RegisterController.log.error(var5.getMessage(), var5);
               throw new WebResException("500", new Object[]{"聚合服务注册删除异常"});
            }
         }
      }).sendRequest(new Object[0]);
   }
}
